﻿<?php require_once('Connections/satphp.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}


if(@isset($_GET['iddisciplina']) && @!isset($_GET['idaula']) && $_GET['iddisciplina'] != ""){

$iddisciplina = @$_GET['iddisciplina'];
mysql_select_db($database_satphp, $satphp);
$query_Recordset1 = "SELECT disciplina.nome, disciplina.iddisciplina, aula.`data`, aula.conteudo, aula.aulas, aula.idaula FROM disciplina JOIN aula ON(aula.iddisciplina = disciplina.iddisciplina) WHERE  disciplina.iddisciplina = $iddisciplina ORDER BY aula.`data` desc";
$Recordset1 = mysql_query($query_Recordset1, $satphp) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

if(@isset($_GET['del'])){
	$idaula = @$_GET['del'];
	mysql_select_db($database_satphp, $satphp);
	$query_Recordset2 = "DELETE FROM aula WHERE idaula = $idaula";
	$Recordset2 = mysql_query($query_Recordset2, $satphp) or die(mysql_error());
	header ("Location: aula-listar.php?iddisciplina=$iddisciplina");
}

mysql_select_db($database_satphp, $satphp);
$query_Recordset3 = "SELECT disciplina.nome FROM disciplina WHERE disciplina.iddisciplina = $iddisciplina";
$Recordset3 = mysql_query($query_Recordset3, $satphp) or die(mysql_error());
$row_Recordset3 = mysql_fetch_assoc($Recordset3);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aulas | SATPHP</title>
</head>

<body>
<p>
<h1 align="center">Aulas da disciplina de <?php echo $row_Recordset3['nome'];?> </h1>
</p>
<table width="581" border="0" align="center">
  <tr>
    <td width="80"><strong>Qtd. Aulas</strong></td>
    <td width="200"><strong>Conteúdo</strong></td>
    <td width="115"><strong>Data</strong></td>
    <td width="47"><strong>Ações</strong></td>
  </tr>
  <?php if ($totalRows_Recordset1 > 0){ do{ ?>
  <tr>
    <td><?php echo $row_Recordset1['aulas']; ?></td>
    <td><?php echo $row_Recordset1['conteudo']; ?></td>
    <td><?php echo $row_Recordset1['data']; ?></td>
    <td><a href="aula-nova.php?idaula=<?php echo $row_Recordset1['idaula']; ?>"><img src="imagens/editar.png" width="22" height="22" border="0" align="middle" title="editar"/></a><a href="aula-listar.php?iddisciplina=<?php echo $row_Recordset1['iddisciplina']; ?>&del=<?php echo $row_Recordset1['idaula'];?>"><img src="imagens/apagar.png" width="25" height="25" border="0" align="middle" title="apagar"/></a></td>
  </tr>
  <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); } else {?>
  <tr>
    <td colspan="4" align="center"> Nenhuma aula encontrada</td>
  <tr>
    <?php } ?>
  <tr>
    <td colspan="4" align="center"><a href="aula-nova.php?iddisciplina=<?php echo $iddisciplina;?>">Nova aula</a></td>
  <tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);} else include("error-page.html");
?>
